import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/layout',
    component: () => import('../views/Layout.vue'),
    children:[
      {
        path: '/layout/home',
        meta:{title:'首页',icon:'shop-o'},
        component: () => import('../views/Home.vue'),
      },
      {
        path: '/layout/list',
        meta:{title:'分类',icon:'apps-o'},
        component: () => import('../views/List.vue'),
      },
      {
        path: '/layout/cart',
        meta:{title:'购物车',icon:'shopping-cart-o'},
        component: () => import('../views/Cart.vue'),
      },
      {
        path: '/layout/my',
        meta:{title:'我的',icon:'contact'},
        component: () => import('../views/My.vue'),
      },
    ]
  },
  {
    path: '/sear',
    component: () => import('../views/Search.vue')
  },
  {
    path: '/detail',
    component: () => import('../views/Detail.vue')
  },
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// router.beforeEach((to, from,next) => {
//   let token=localStorage.getItem('token');
//   if(!token&&to.path!='/login'&&(to.path!='/layout/home'&&to.path!='/layout/list')){
//     next('/login')
//   }else{
//     next()
//   }
// })
export default router
